<!-- 显示数据的列表 -->
<template>
  <div class="system-download-list-data-list">
    <el-table ref="multipleTable" :data="dataTable" tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange" @select-all="selectAll">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column label="文件名称" prop="downloadName" class-name="cusxx">
        <template slot-scope="scope">
          <TooltipOver :tipValue="scope.row.downloadName" :refTipName="'ref-title-' + scope.row.id"/>
        </template>
      </el-table-column>
      <el-table-column prop="categoryName" label="所属分类" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.categoryId">{{scope.row.categoryName}}</span>
          <span v-else style="color:#999999;">未定义</span>
        </template>
      </el-table-column>
      <el-table-column prop="createAt" label="创建时间" show-overflow-tooltip width="180">
        <template slot-scope="scope">
          {{scope.row.createAt | dateformat}}
        </template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip width="210">
        <template slot-scope="scope">
          <el-button @click="reduceItem(scope.row.id)" type="text">还原</el-button>
          <el-button @click="deleteItem(scope.row.id)" type="text">彻底删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import TooltipOver from '@/components/common/TooltipOver.vue'
export default {
  props: {
    dataTable: {
      type: Array
    },
    data: {
      type: Array
    },
    multipleSelection: {
      type: Array
    },
    multipleSelectionChange: {
      type: Function
    },
    resetData: {
      type: Function
    },
    system: {
      type: Object
    },
    setDataTable: {
      type: Function
    }
  },
  data () {
    return {
      isShow: {},
      isLoading: {}
    }
  },
  watch: {
    dataTable: {
      handler (newValue) {
        if (newValue.length > 0) {
          newValue.forEach(item => {
            this.isShow[item.id] = item.isShow > 0
            this.isLoading[item.id] = false
          })
        } else {
          this.isShow = {}
        }
      },
      deep: true
    }
  },
  methods: {
    // 批量删除选中回调方法
    handleSelectionChange (val) {
      this.multipleSelectionChange(val)
    },
    selectAll (val) {
      if (!val.length && !this.dataTable.length) {
        this.$refs.multipleTable.clearSelection()
      }
    },
    // 还原
    reduceItem (id) {
      let item = this.dataTable.find((element) => {
        return element.id === id
      })
      if (!item) {
        return
      }
      this.$confirm('确认要还原 ' + item.downloadName + ' 下载项？', '提示', {
        type: 'warning'
      })
        .then(() => {
          this.$post('/system/download/reduction-recycle-one', {
            id: id
          }).then((response) => {
            if (response && response.sdownload && response.sdownload.id && parseInt(response.sdownload.id) > 0) {
              this.resetData()
            }
          })
        })
        .catch(() => {
        })
    },
    // 彻底删除
    deleteItem (id) {
      let item = this.dataTable.find((element) => {
        return element.id === id
      })
      if (!item) {
        return
      }

      this.$confirm('确认要彻底删除 ' + item.downloadName + ' 下载项？', '提示', {
        type: 'warning'
      })
        .then(() => {
          this.$post('/system/download/clean-recycle-one', {
            id: id
          }).then((response) => {
            if (response && response.sdownload && response.sdownload.id && parseInt(response.sdownload.id) > 0) {
              this.resetData()
            }
          })
        })
        .catch(() => {
        })
    }
  },
  components: {
    TooltipOver
  }
}

</script>

<style scoped lang="scss">
.system-download-list-data-list /deep/ {
  .el-table th {
    color: #555;
  }
  .el-table-column--selection .cell {
    padding-left: 10px;
  }
}
.system-download-list-data-list .order-num .el-input__inner {
  padding: 0 8px;
}
</style>
